/**
 * @file   ModSql.java
 * @author Enrique Madrid <e.madrid@lpcsite.com>
 * @date   Fri Sep 21 13:48:11 2007
 *
 * @brief
 *
 *
 */

package sim.query;

import java.util.*;

import sim.framework.*;
import sim.framework.io.*;
import sim.forms.*;

public abstract class ModSql extends ModForm {
    
    private int m_Field = 0;
    private byte[] m_Value = null;
    
    public ModSql(int id, Simlet s) {
        super(id, s);
    }
    
    public int getField() {
        return m_Field;
    }
    
    public byte[] getValue() {
        return m_Value;
    }
    
    public void formGoToNext() {
        Vector nodes;
        FrmNode node = null;
        String option;
        
        //#ifdef DEBUG_MODSQL
        //# System.out.println("ModSql::formGoToNext() ENTERED");
        //#endif
        
        nodes = getOptions();
        // Si hay mas de una opción busqueda, el segundo tiene los datos.
        node = (nodes.size() > 1) ? (FrmNode)nodes.elementAt(1) : (FrmNode)nodes.elementAt(0);
        if (node != null) {
            // El id del nodo es la posición del campo.
            m_Field = node.getId();
            // El valor del nodo es el valor a buscar.
            option = node.getOption();
            m_Value = (option.compareTo("") == 0) ? null : option.getBytes();
            //#ifdef DEBUG_MODSQL
            //# System.out.println("\tm_Field = " + m_Field);
            //# System.out.println("\tm_Value = " + ((m_Value == null) ? "null" : option));
            //#endif
        }
        
        super.formGoToNext();
        
        //#ifdef DEBUG_MODSQL
        //# System.out.println("ModSql::formGoToNext() EXITING");
        //#endif
    }
    
    protected final Form formCreate() {
	return Form.create(m_Simlet, sqlFileName());
    }
    
    protected abstract String sqlFileName();
    
    protected String formBQuitLabel(final FrmNode node) {
        return null;
    }
}
